//Boxy插件的扩展
jQuery.fn.qbox = function (options) {
    var node = this.get(0).nodeName.toLowerCase();
    var self = this;
    if (node == 'a') {
        $(this).attr('onclick', '').unbind('click').click(function () {
            return false;
        });
        options = $.extend({src:this.get(0).getAttribute('href'), beforeUnload:function () {
            $(self).unbind('click').click(function () {
                return $(this).qbox(options);
            });
        }}, options || {});
    }
    qBox.iFLoad(options);
    return false;
}
var qBox = function () {
};
jQuery.extend(qBox, {
    aDgs:[],
    customSize: false,
    loadResize: false,
    iFrame:function (op) {
        var defaultWidth = 600;
        var defaultHeight = 200;

        if(op.w != undefined && op.w != defaultWidth || op.w != undefined && op.h != defaultHeight) {
            qBox.customSize = true;
        } else {
            qBox.customSize = false;
        }

        op = jQuery.extend({title:'提示', w:defaultWidth, h:defaultHeight, src:'about:blank', modal:false, fixed:false, unloadOnHide:true}, op), fm = parseInt(Math.random() * (1000 * 987));//
        var dialog = new Boxy("<b id=\"ld" + fm + "\" style=\"width: 400px;height: 100px\">正在加载，请稍后....</b><iframe id=\"_" + fm + "\" style=\"width:0px;height:0px;display:none;padding:0;\" src=" + op.src + " frameborder=\"0\" scrolling=\"no\"></iframe>", op);

        jQuery("#_" + fm).load(function () {
            dialog.resize(op.w, op.h, function () {});

            if(!qBox.customSize) {
                var height = $(this).contents().find("body").height() + 10;
                var width = $(this).contents().find("body").width() + 10;
                dialog.resize(width, height, function () {});
                qBox.loadResize = true;
            }

            jQuery("#ld" + fm).remove();
            jQuery("#_" + fm).css({'display':''});
        });
        qBox.aDgs.push(dialog);
        return false;
    },
    resizeOnly: function(width, height) {
        if(!qBox.customSize) {
            var B = qBox.aDgs[qBox.aDgs.length - 1];
            B.resizeOnly(width, height, function () {});
        }
    },
    Close:function () {
        qBox.aDgs[qBox.aDgs.length - 1].hide();
        return false
    },
    iFSrc:function (op) {
        var defaultWidth = 320;
        var defaultHeight = 200;

        if(op.w != undefined && op.w != defaultWidth || op.w != undefined && op.h != defaultHeight) {
            qBox.customSize = true;
        }

        op = jQuery.extend({w:defaultWidth, h:defaultHeight, src:'about:blank'}, op);
        var B = qBox.aDgs[qBox.aDgs.length - 1];
        B.setTitle(op.title);
        B.getContent().attr({'src':op.src});
        B.tween(op.w, op.h, function () {
            B.getContent().css({'width':op.w + 'px', 'height':op.h + 'px'});
        });
        return false;
    },
    iFLoad:function (options) {
        var sr = jQuery(this).attr("href");
        var op = jQuery.extend({src:sr}, options);
        qBox.iFrame(op);
        return false;
    }
});